package org.fujene.communicate.deleter;

import org.fujene.communicate.MainServiceSettings;

public class DeleterPackage implements Comparable<DeleterPackage>{
	public static final int TYPE_ID = MainServiceSettings.DELTYPE_ID;
	public static final int TYPE_CONTENT = MainServiceSettings.DELTYPE_CONTENT;
	public static final int TYPE_FLAG = MainServiceSettings.DELTYPE_MULTIFLAG;

	private String strval;
	private int flagval;
	private long ID;
	private int type;
	private int cluster;

	public DeleterPackage(String strval){
		this.strval = strval;
		this.type = TYPE_CONTENT;
	}

	public DeleterPackage(int flagval){
		this.flagval = flagval;
		this.type = TYPE_FLAG;
	}

	public DeleterPackage(long ID){
		this.ID = ID;
		this.type = TYPE_ID;
	}

	public void setCluster(int cluster){
		this.cluster = cluster;
	}

	public int type(){
		return type;
	}

	public String strval(){
		if(type == TYPE_CONTENT) return strval;
		return null;
	}

	public int flagval(){
		if(type == TYPE_FLAG) return flagval;
		return Integer.MIN_VALUE;
	}

	public long ID(){
		if(type == TYPE_ID) return ID;
		return Long.MIN_VALUE;
	}

	public int cluster(){
		return cluster;
	}

	@Override
	public boolean equals(Object obj){
		if(obj instanceof DeleterPackage){
			DeleterPackage others = (DeleterPackage)obj;
			if(this.type == others.type){
				if(this.type == TYPE_ID && this.ID == others.ID) return true;
				if(this.type == TYPE_FLAG && this.flagval == others.flagval) return true;
				if(this.type == TYPE_CONTENT && this.strval.equals(others.strval)) return true;
			}
		}
		return super.equals(obj);
	}

	@Override
	public int compareTo(DeleterPackage o){
		// Fifth sort
		if(this.type > o.type) return 1;
		if(this.type < o.type) return -1;
		if(this.cluster > o.cluster) return 1;
		if(this.cluster < o.cluster) return -1;
		if(this.type == TYPE_ID && this.ID > o.ID) return 1;
		if(this.type == TYPE_ID && this.ID < o.ID) return -1;
		if(this.type == TYPE_FLAG && this.flagval > o.flagval) return 1;
		if(this.type == TYPE_FLAG && this.flagval < o.flagval) return -1;
		if(this.type == TYPE_CONTENT && this.strval.compareTo(o.strval) > 0) return 1;
		if(this.type == TYPE_CONTENT && this.strval.compareTo(o.strval) < 0) return -1;
		return 0;
	}
}
